﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PegasCompany.Data;
using PegasCompany.Helper;
using PegasCompany.Tools;

namespace PegasCompany.Master
{
    public partial class ViewPageStandart : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                FillYearList();
            }
        }

        private void FillYearList()
        {
            IOrderedEnumerable<int> lYearList = SiteContent.ListAllContentYear((int)EnumHelper.ListContentType.News).OrderByDescending(i => i);
            rptArchive.DataSource = lYearList;
            rptArchive.DataBind();
        }

        protected IEnumerable<string> FillMonthList(object oYear)
        {
            if (!(oYear is int)) return null;
            
            int iYear = Convert.ToInt32(oYear);
            List<int> distinctMonth = SiteContent.ListAllContentYearMonth((int) EnumHelper.ListContentType.News, iYear);

            if (distinctMonth == null) return null;

            DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(CultureInfo.GetCultureInfo("ru-RU"));
            return distinctMonth.Select(i => info != null ? info.GetMonthName(i) : null).ToList();
        }

        

        //protected void FillMonth(object oYear)
        //{
        //    if (oYear is int)
        //    {
        //        List<int> distinctMonth = SiteContent.ListAllContentYearMonth((int)EnumHelper.ListContentType.News)
        //    }
        //}

        //protected void FillYears()
        //{
        //    List<int> distinctYear = SiteContent.ListAllContentYear((int)EnumHelper.ListContentType.News, true);


        //    foreach (int i in distinctYear)
        //    {
        //        List<int> distinctMonth = scList.Select(p => p.CreateDate != null ? new { i, p.CreateDate.Value.Month } : null).Distinct().ToList().Select(x => x.Month).ToList();
        //    }
        //}
    }
}